/**
 * @author smallwang
 * @email justdoalitter@gmail.com
 * @create date 2025-01-30 00:43:58
 * @modify date 2025-01-30 00:43:58
 * @desc [description]
 */
package ltd.smallwang;

import ltd.smallwang.common.ListNode;

public class Leetcode0141 {

  public boolean hasCycle(ListNode head) {
    if (head == null || head.next == null) {
      return false;
    }
    ListNode slow = head;
    ListNode fast = head.next;
    while (slow != null && fast != null) {
      if (slow == fast) {
        return true;
      }
      slow = slow.next;
      fast = fast.next;
      if (fast == null) {
        continue;
      }
      fast = fast.next;
    }
    return false;
  }
}
